Learn R Programming

colleyRstats (version 0.0.1)

data the data frame: Replace values across a data frame

Description

Replace all occurrences of given values in all columns of a data frame.

The data data frame contains a collection of records, with attributes organized in columns. It may include various types of values, such as numerical, categorical, or textual data.

Usage

replace_values(data, to_replace, replace_with)

Value

Modified data frame with specified values replaced.

Arguments

data

The input data frame to be modified.

to_replace

A vector of values to be replaced within the data frame. This must be the same length as replace_with.

replace_with

A vector of corresponding replacement values. This must be the same length as to_replace.

Examples

Run this code
# \donttest{
data <- data.frame(
  q1 = c("neg2", "neg1", "0"),
  q2 = c("1", "neg2", "neg1")
)

replace_values(
  data,
  to_replace = c("neg2", "neg1"),
  replace_with = c("-2", "-1")
)
# }

Run the code above in your browser using DataLab